 <%@ page language="java" import="java.util.*" pageEncoding="utf-8" import="pojo.*,base.*,service.*,java.text.*,java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<html>
<head>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.minus,.plus{

cursor:pointer;

 }
 .plus{
 
 margin-right:15px;
 
 }
 .aa{
         margin-left: 1270px;
 }
 .container{
     width:400px;
     margin-left:10px
 }
</style>
<script type="text/javascript" src="../jquery/jquery-1.6.1.js"></script>
<script type="text/javascript" src="../jquery/jquery.validate.min.js"></script>

<script >
 function deleteDish(url){
  if(deleteconfirm()){
  location.href=url;
  }
 }
 function deleteconfirm(){
	if(confirm("确认要删除此菜品信息？"))
		return true;
	return false;
 }
 	function getParam(){
 		 minus=$(".list").find(".minus");
		 plus=$(".list").find(".plus");
		 price=$(".list").find(".price");
		 total=$(".list").find(".total");
		 num=$(".list").find(".num");
		 sale=$(".list").find(".sale");
		 size=$(".list").size();
 	}
	function totalmoney(){
		var size=$(".list").size();
		var totalmoney=0;
		for(i=0;i<size;i++){
			totalmoney+=parseFloat($(".list").eq(i).find(".total").text());
		}
		$("#totalmoney").text(parseFloat(totalmoney).toFixed(1));
		$("#totalprice").val(parseFloat(totalmoney).toFixed(1));
		
	}
	function sum(index,i){
		getParam();
		var n=parseInt(num.eq(index).val())+i;
		if(!isNaN(parseInt($(".list").eq(index).find(".sale").text()))){
			money=parseFloat(n*parseFloat(price.eq(index).text())*parseInt($(".list").eq(index).find(".sale").text())/10).toFixed(2);
		}else{
			money=parseFloat(n*parseFloat(price.eq(index).text())).toFixed(2);
		}
	    num.eq(index).val(n);
		total.eq(index).text(money);		
		totalmoney();	
	}

	$(function(){	
		getParam();	
		for(i=0;i<size;i++){
			if(!isNaN(parseInt($(".list").eq(i).find(".sale").text()))){
				total.eq(i).text(parseFloat(parseInt($(".list").eq(i).find(".num").val())*parseFloat($(".list").eq(i).find(".price").text())*parseInt($(".list").eq(i).find(".sale").text())/10).toFixed(2));
			}else{
				total.eq(i).text(parseFloat(parseInt($(".list").eq(i).find(".num").val())*parseFloat($(".list").eq(i).find(".price").text())).toFixed(2));
			}
		}
		$(".minus").click(function(){
			var index=minus.index(this);
			if(num.eq(index).val()>1){
			sum(index,-1);										
			}else{alert("不能小于1");return;}
		})
		$(".plus").click(function(){
			var index=plus.index(this);
			if(num.eq(index).val()>4){
			alert("不能大于5个");
			return;										
			}
			else{sum(index,1);}
			
		})
		$(".num").keyup(function(){
			var index=num.index(this);
			var n=num.eq(index).val();
			if(!(n.match(/\D/)===null)||n==0||n>5){
				alert("数量格式不合法");
				num.eq(index).val(1);
				return;
			}else{
			total.eq(index).text(parseFloat(parseInt(num.eq(index).val())*parseFloat(price.eq(index).text())).toFixed(1));
			totalmoney();
			}
		})	
	})
 </script>
 <script type="text/javascript">
$(function(){
	$("#ok").click(function(){
	var id=$("input[name='id']").eq(0).val();
	if(id==""||id==null||id==undefined){alert("您还没有点菜!!");return;}
	var tel=$("#tel").val();
	var IDcard=$("#IDcard").val();
	var realname=$("#realname").val();
	if(realname==""){
	alert("请输入真实姓名");
	return false;
	}
    if(tel==""){
	alert("请输入先用手机号");
	return false;
	}
	if(IDcard==""){
	alert("请输入身份证号");
	return false;
	}
	
	if(tel!=""){
	if(!(/^(1)\d{10}$/).test(tel)){
        alert("请输入正确的格式的手机号");
        $("#tel").focus();
        return false;
    }else{ $("#form1").submit()}
    }

    if(IDcard!=""){
    if(!(/^[1-9]([0-9]{14}|[0-9]{16}[x]|[0-9]{17})$/).test(IDcard)){
    alert("请输入正确格式的身份证号");
    $("#IDcard").focus();
       return false;
    }
    else{ $("#form1").submit()}
   
    }
    else{$("#form1").submit()}
    
	})
})
</script>

  </head>
  
  <body onload="totalmoney();">
   <div class="navbar navbar-inverse navbar-fixed-top">
       <div class="navbar-inner">
           <div class="container-fluid">
                   <a class="brand" href="index.jsp">白金汉宫网上订餐</a>
              <div class="nav-collapse collapse">
         
                  <ul class="nav">
                    <li class="active">
                        <a href="#">主页</a>
                    </li>
                  </ul>
      <p class="navbar-text pull-right">
<%
        
		String username = (String)session.getAttribute( "name" );
		CartService cs= new CartService();
		if ( username == null || username == "" )
		{
%>
<a class="navbar-link" href="login.jsp">登录</a>&nbsp;&nbsp;&nbsp;<a class="navbar-link" href="regest.jsp">注册</a>
<%
} 
		    else
		        {
		              int userid=(Integer)session.getAttribute("id");
		              int cartNum=cs.getALL(userid);
			                out.println( "欢迎您! "+username  );
			                out.println("<a href='memberzone.jsp' role='button' class='btn btn-success' >个人中心</a>");
			                out.println("<a href='cartlist.jsp' data-placement='bottom' role='button' class='btn btn-warning' data-toggle='tooltip' title=''>我的购物车"+cartNum+"</a>");
			                out.println( "<a href='destroySession.jsp' role='button' class='btn btn-danger' >安全退出</a>" );
		}
%>






</p>
	   </div>   
         </div>
            </div>
              </div>


<%
	request.setCharacterEncoding("utf-8");
    int size=cs.getALL((Integer)session.getAttribute("id"));//获取总数量
    String spageno = request.getParameter("pageno");
    int pageno;//页码
    int pagesize=9;//每页显示行数
    if(spageno==null){ pageno = 1;}//当页码为空时默认为1
    else pageno=Integer.parseInt(request.getParameter("pageno"));//否则为传过来的页码
	try{pageno = Integer.parseInt(spageno);}
	catch(Exception e){}
	Page p1=new Page();
								p1.setTotalRecord(size);
								p1.setCurrentPageNo(pageno);
								p1.setPageSize(pagesize);
								
	int userId = (Integer)session.getAttribute("id");	
	List<dishes> list = cs.getDishes(pageno,pagesize,userId);//按参数查询	
	DishesService dts=new DishesService();
		
%>

<form id="form1" method="post" action="../action/websiteAction/PostOrderAction.jsp">
 <div class="span3 " style="align:left;"><strong><h1>菜单信息</h1></strong></div><br/>
	<table class="table table-hover">
      <tr>
        <td ><div align="center">菜品名称</div></td>
        <td ><div align="center">菜品种类</div></td>
        <td ><div align="center">菜品图片</div></td>
        <td ><div align="center">菜品数量</div></td>
        <td ><div align="center">菜品价格</div></td>
        <td ><div align="center">有无折扣</div></td>
        <td ><div align="center">消费小计</div></td>
        <td ><div align="center">删除</div></td>
      </tr>
<%
    int dishesNum=1;
   // session.setAttribute("dishesList",list);
	for (dishes dt : list) {
	out.println("<input type='hidden' name='id' value='"+dt.getId()+"'>");
    out.println("<tr class='list'><td>"+dt.getName()+"</td>");
	out.println("<td>"+dts.getType(dt.getType()).getName()+"</a></td>");
	out.println("<td><img WIDTH=50 HEIGHT=50 src='../"+dt.getPicture()+"'></td>");
	out.println("<td><span class='minus'>-</span><input style='width:80px;' type='text' name='ordernum' id='text1' class='num'value='"+dishesNum+"'><span class='plus'>+</span></td>");
	out.println("<td><span class='price'>"+dt.getPrice()+"元</span></td>");
	if (dt.getSale()==10){
	      out.println("<td> </td>");
	}
	else 
	      out.println("<td><span class='sale'>"+dt.getSale()+"</span>折</td>");
	      
	float partprice= dt.getPrice()*dishesNum*dt.getSale()/10;
	out.println("<td><span class='total' >"+partprice+"元</span></td>");
	out.println("<td><button class='btn btn-small btn-primary' type='button' onclick=deleteDish('../action/websiteAction/deleteCart.jsp?id="+dt.getId()+"');>删除</button></td></tr></div>");
	}
	%>
	
	<%
	float totalprice=cs.gettotalprice(userId);
	int a=cs.getALL(userId);
	out.print("<tr><td colspan='9'>您共点了<span id='a'>"+a+"</span>个菜!!!总消费额:<span id='totalmoney'>"+totalprice+"</span>元</td><input type='hidden' name='totalprice' id='totalprice' /></tr>");
	out.print("<tr><td colspan='9'><h5>共"+p1.getTotalPage()+"页，当前第"+pageno+"页， ---<a href='cartlist.jsp?&pageno="+p1.getPrePage()+"'>上一页</a>");
								 out.print("<a href='cartlist.jsp?&pageno="+p1.getNextPage()+"'>下一页</a></h5></td></tr>");


%>
	    
</table>
<hr>
<div class="container">
    

<%

 TableService ts= new TableService();
if(session.getAttribute("date")==null){
          out.println("<div class='span5 '><strong><h1>预订餐桌情况</h1></strong></div><br/>");
          out.println("<p class='text-error'>您还没有预订餐桌！！！！</p> <a href='index.jsp'>去选餐桌</a>");
}
else {
      int tabletype = (Integer)session.getAttribute("tabletype");

        out.println("<div class='span5 '><strong><h1>预订餐桌情况</h1></strong></div><br/>");
          out.println("<div class='span5' style='margin-top:20px;'><p class='text-success'>就餐时间："+session.getAttribute("date")+"</p></div><br/>");
           out.println("<div class='span5' style='margin-top:20px;'><p class='text-success'>餐桌位置："+session.getAttribute("tablearea")+"</p><p class='text-error'>注：1代表大厅，2代表包厢</p></div><br/>");
            out.println("<div class='span5' style='margin-top:20px;'><p class='text-success'>餐桌类型："+ts.getType(tabletype).getName()+"</p></div><br/>");
            out.println("<div class='span5' style='margin-top:20px;margin-top:20px;'><p class='text-success'>就餐时段:"+session.getAttribute("type")+"</p><p class='text-error'>注：1代表午餐档，2代表晚餐档</p></div>");
              out.println("<p class='text-warning'>注：如要改变餐桌信息，请重新预订！！！</p>");
}




 %>
</div>
<hr>
<div class="container">
    
<div class="span5 "><strong><h1>请输入个人信息</h1></strong></div><br/>
<input class="input-block-level" type="text" id="realname" name="realname" placeholder="真实姓名" ><br/>
<input class="input-block-level" type="text" id="tel" name="tel" placeholder="电话号码"><br/>
<input class="input-block-level" type="text" id="IDcard" name="IDcard" placeholder="身份证号码"><br/><br/>
<p class="text-error">注：三项均为必填！为方便您的订餐，请填写有效信息！！！</p>
</div>
<div class="aa"><button class="btn btn-large btn-primary" type="button" id="ok">提交</button></div>.
</form>
  </body>
</html>
